import 'dart:io';

import 'package:flutter/material.dart';
import 'package:untitled/widgets/common_float_action_button.dart';
import 'package:untitled/widgets/common_form_item.dart';
import 'package:untitled/widgets/common_image_picker.dart';
import 'package:untitled/widgets/common_radio_form_item.dart';
import 'package:untitled/widgets/common_select_form_item.dart';
import 'package:untitled/widgets/common_title.dart';
import 'package:untitled/widgets/room_appliance.dart';

//添加房屋页面

class RoomAddPage extends StatefulWidget {
  const RoomAddPage({Key key}) : super(key: key);

  @override
  _RoomAddPageState createState() => _RoomAddPageState();
}

class _RoomAddPageState extends State<RoomAddPage> {
  int rentType = 0;//租聘方式
  int decorationType = 0;//装修方式

  int roomType = 0;//房间类型
  int floor = 0;//楼层号
  int oriented = 0;//楼层朝向

  var titleController = TextEditingController();
  var descController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('发布房源'),
      ),
      body: ListView(
        children: [
          CommonTitle('房源信息'),
          CommonFormItem(
            label: '小区',
            contentBuilder: (context) {
              return Container(
                child: GestureDetector(
                    onTap: () {
                      Navigator.of(context).pushNamed('search');
                    },
                    behavior: HitTestBehavior.translucent,
                    //点击GestureDetector的空白区域也生效点击事件
                    child: Container(
                      height: 40,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '请选择小区',
                            style: TextStyle(fontSize: 16.0),
                          ),
                          Icon(Icons.keyboard_arrow_right)
                        ],
                      ),
                    )),
              );

            },
          ),
          CommonFormItem(
            label: '租金',
            hintText: '请输入租金',
            suffixText: '元/月',
            controller: TextEditingController(),
          ),
          CommonFormItem(
            label: '大小',
            hintText: '请输入房屋大小',
            suffixText: '平方',
            controller: TextEditingController(),
          ),
          CommonRadioFormItem(
            label: '租赁方式',
            options: ['合租','整租'],
            value: rentType,
            onChange: (index){
              setState(() {
                rentType = index;
              });
            },
          ),
          CommonSelectFormItem(
            label: '户型',
            value: roomType,
            onChange: (val){
              setState(() {
                roomType = val;
              });
            },
            options: [
              '一室',
              '二室',
              '三室',
              '四室',
              '其他'
            ],
          ),
          CommonSelectFormItem(
            label: '楼层',
            value: floor,
            onChange: (val){
              setState(() {
                floor = val;
              });
            },
            options: [
              '高楼层',
              '中楼层',
              '低楼层'
            ],
          ),
          CommonSelectFormItem(
            label: '朝向',
            value: oriented,
            onChange: (val){
              setState(() {
                oriented = val;
              });
            },
            options: [
              '东',
              '南',
              '西',
              '北'
            ],
          ),
          CommonRadioFormItem(
            label: '装修',
            options: ['精装','简装'],
            value: decorationType,
            onChange: (index){
              setState(() {
                decorationType = index;
              });
            },
          ),

          CommonTitle('房屋头像'),
          CommonImagePicker(
            onChange:(List<File> files){},
          ),
          CommonTitle('房屋标题'),
          Container(
            //设置水平间距为10
            padding: EdgeInsets.symmetric(horizontal: 10.0),
            child: TextField(
              maxLength: 50,//最大能输入文字个数
              controller: titleController,
              decoration: InputDecoration(
                  border: InputBorder.none,//去除下划线
                  hintText: '请输入标题（例如：整租，小区名 2室2000元）'
              ),
            ),
          ),
          CommonTitle('房屋配置'),
          RoomAppliance(
            onChange: (data){

            },
          ),
          CommonTitle('房屋描述'),
          Container(
            //不加margin会被底下的提交按钮挡住
            margin: EdgeInsets.only(bottom: 100),
            //设置水平间距为10
            padding: EdgeInsets.symmetric(horizontal: 10.0),
            child: TextField(
              maxLength: 200,
              controller: descController,
              maxLines: 10,
              decoration: InputDecoration(
                  border: InputBorder.none,//去除下划线
                  hintText: '请输入房屋描述信息'
              ),
            ),
          ),
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: CommonFloatingActionButton('提交', () {}),
    );
  }
}
